﻿using FamilyBook.Core;
using FamilyBook.Core.Configuration;

namespace FamilyBook.Repository.EF
{
    public class DbSession : IDbSession
    {
        private FamilyBookDbContext _dbContext;

        public DbSession(IConfiguration config)
        {
            _dbContext = new FamilyBookDbContext(config.DbConnection);
        }

        public object DbContext { get { return _dbContext; } }

        public void Dispose()
        {
            if (_dbContext != null)
            {
                _dbContext.Dispose();
                _dbContext = null;
            }
        }
    }
}
